<!--阿里云配置-->
<template>
  <div class="ele-body">
    <el-row :gutter="15">
      <el-col :span="24">
        <el-card shadow="never"
                 style="margin-bottom: 10px"
                 body-style="padding: 0;">
          <el-form style="max-width: 450px; padding: 34px 20px 0 20px"
                   @keyup.enter.native="save"
                   @submit.native.prevent>
            <el-form-item label="微信:"
                          prop="wxPayType">
              <el-radio v-model="wxPayType"
                        label="4"
                        @change="wxPayTypeFn('4')">不启动</el-radio>
              <el-radio v-model="wxPayType"
                        label="1"
                        @change="wxPayTypeFn('1')">启动</el-radio>
              <div v-if="isWxMerchantPayment">
                <el-form-item prop="wxPayStatus"
                              label-width="44px">
                  <el-radio v-model="wxPayStatus"
                            label="2"
                            @input="wxPayStatusFn">V3商户支付</el-radio>
                  <el-radio v-model="wxPayStatus"
                            @input="wxPayStatusFn"
                            label="1">特约子商户支付</el-radio>
                </el-form-item>
              </div>
            </el-form-item>

            <el-form-item label="支付宝:"
                          prop="zfbPayType">
              <el-radio v-model="zfbPayType"
                        @change="zfbPayTypeFn('4')"
                        label="4">不启动</el-radio>
              <el-radio v-model="zfbPayType"
                        @change="zfbPayTypeFn('2')"
                        label="2">启动</el-radio>
              <div v-if="isZfbMerchantPayment">
                <el-form-item prop="zfbPayStatus"
                              label-width="57px">
                  <el-radio v-model="zfbPayStatus"
                            label="4"
                            @input="zfbPayStatusFn">普通商户支付</el-radio>
                  <el-radio v-model="zfbPayStatus"
                            label="3"
                            @input="zfbPayStatusFn">间连商户支付</el-radio>
                </el-form-item>
              </div>
            </el-form-item>
            <!-- <el-form-item label="现金返现:"
							prop="zfbPayType">
  
				<el-radio-group v-model="returnCashType">
				  <el-radio @change="cashCashbackFn('1')"
							label="1">固定金额</el-radio>
				  <el-radio @change="cashCashbackFn('2')"
							label="2">付款比例</el-radio>
				</el-radio-group>
  
			  </el-form-item>
			  <div v-if="returnCashType=='1'">
				<el-form-item label="返现金额:"
							  prop="returnCashAmount">
				  <el-input min="0"
							type="number"
							v-model.number="returnCashAmount">
					<template slot="prepend">返现</template>
					<template slot="append">元</template>
				  </el-input>
  
				</el-form-item>
			  </div>
			  <div v-if="returnCashType=='2'">
				<el-form-item label="返现比例:"
							  prop="returnCashRatio">
				  <el-input min="0"
							max="100"
							type="number"
							v-model.number="returnCashRatio">
					<template slot="prepend">返现</template>
					<template slot="append">%</template>
				  </el-input>
  
				</el-form-item>
			  </div> -->
            <!-- 
			  <el-form-item label="返现时间:"
							prop="returnCashTime">
				<el-input min="0"
						  type="number"
						  v-model.number="returnCashTime">
				  <template slot="prepend">返现</template>
				  <template slot="append">小时</template>
				</el-input>
  
			  </el-form-item> -->
            <el-form-item>
              <el-button type="primary"
                         :loading="typeloading"
                         @click="saveInfo()">
                保存配置
              </el-button>
            </el-form-item>

          </el-form>
        </el-card>
      </el-col>
    </el-row>
    <el-row :gutter="15">
      <el-col :span="24">
        <el-card shadow="never"
                 body-style="padding: 0;">
          <el-tabs v-model="active"
                   @tab-click="handleClick"
                   class="user-info-tabs">
            <el-tab-pane label="微信"
                         name="1">
              <div class="checkPayment">
                <el-radio v-model="wxMerchant"
                          label="2"
                          @change="clearFieldsFn('wxForm')">V3商户支付</el-radio>

                <el-radio v-model="wxMerchant"
                          label="1"
                          @change="clearFieldsFn('wxServiceForm')">特约子商户支付</el-radio>
              </div>

              <!-- 微信普通商户 -->
              <div v-show="wxMerchant == '2'">
                <el-form ref="wxForm"
                         :model="wxForm"
                         :rules="rulesWxForm"
                         label-width="180px"
                         style="max-width: 650px; padding: 34px 20px 0 20px"
                         @keyup.enter.native="save"
                         @submit.native.prevent>
                  <el-form-item label="微信appid:"
                                prop="appid">
                    <el-input v-model.trim="wxForm.appid"
                              show-password
                              placeholder="请输入微信appid"
                              clearable />
                  </el-form-item>

                  <el-form-item label="直连商户号:"
                                prop="mchid">
                    <el-input v-model.trim="wxForm.mchid"
                              show-password
                              placeholder="请输入直连商户号"
                              clearable />
                  </el-form-item>

                  <el-form-item label="APIv3密钥:"
                                prop="appV3Key">
                    <el-input v-model.trim="wxForm.appV3Key"
                              show-password
                              placeholder="请输入APIv3密钥"
                              clearable />
                  </el-form-item>

                  <el-form-item label="证书序列号:"
                                prop="merchantSerialNumber">
                    <el-input v-model.trim="wxForm.merchantSerialNumber"
                              show-password
                              placeholder="请输入证书序列号"
                              clearable />
                  </el-form-item>

                  <el-form-item label="私钥:"
                                prop="privateKeyPath">

                    <div class="useMouse">
                      <el-input type="textarea"
                                @focus="focusInput('wxForm')"
                                @blur="blurInput('wxForm')"
                                :class="[isShowPassword? 'password':'']"
                                resize="none"
                                v-model.lazy.trim="wxForm.privateKeyPath"
                                @change="(e) => filterText(e, 'wxForm')"
                                placeholder="请输入私钥"
                                clearable> </el-input>
                      <i slot="suffix"
                         style=" color:#c0c4cc"
                         v-if="wxFormIsShowEyeIcon"
                         class="el-input__icon el-icon-view fixed"
                         @click="showPasswordFn()"></i>
                    </div>
                  </el-form-item>
                  <el-form-item>
                    <el-button type="primary"
                               :loading="loading"
                               @click="save('wxForm')">

                      保存配置

                    </el-button>
                  </el-form-item>
                </el-form>
              </div>
              <!--  微信特约子商户-->
              <div v-show="wxMerchant == '1'">
                <el-form ref="wxServiceForm"
                         :model="wxServiceForm"
                         :rules="rulesWxServiceForm"
                         label-width="180px"
                         style="max-width: 650px; padding: 34px 20px 0 20px"
                         @keyup.enter.native="save"
                         @submit.native.prevent>
                  <el-form-item label="服务商应用ID:"
                                prop="spAppid">
                    <el-input v-model.trim="wxServiceForm.spAppid"
                              show-password
                              placeholder="请输入服务商应用ID"
                              clearable />
                  </el-form-item>
                  <el-form-item label="服务商户号:"
                                prop="spMchid">
                    <el-input v-model.trim="wxServiceForm.spMchid"
                              show-password
                              placeholder="请输入服务商户号"
                              clearable />
                  </el-form-item>
                  <el-form-item label="子商户号:"
                                prop="subMchid">
                    <el-input v-model.trim="wxServiceForm.subMchid"
                              show-password
                              placeholder="请选择子商户号"
                              clearable />
                  </el-form-item>

                  <el-form-item label="APIv3密钥:"
                                prop="appV3Key">
                    <el-input v-model.trim="wxServiceForm.appV3Key"
                              show-password
                              placeholder="请输入APIv3密钥"
                              clearable />
                  </el-form-item>

                  <el-form-item label="证书序列号:"
                                prop="merchantSerialNumber">
                    <el-input v-model.trim="wxServiceForm.merchantSerialNumber"
                              show-password
                              placeholder="请输入证书序列号"
                              clearable />
                  </el-form-item>

                  <el-form-item label="私钥:"
                                prop="privateKeyPath">
                    <div class="useMouse">
                      <el-input type="textarea"
                                @focus="focusInput('wxServiceForm')"
                                @blur="blurInput('wxServiceForm')"
                                :class="[isShowPasswordWx? 'password':'']"
                                resize="none"
                                v-model.lazy.trim="wxServiceForm.privateKeyPath"
                                @change="(e) => filterText(e, 'wxServiceForm')"
                                placeholder="请输入私钥"
                                clearable> </el-input>
                      <i slot="suffix"
                         style=" color:#c0c4cc"
                         v-if="wxServiceFormIsShowEyeIcon"
                         class="el-input__icon el-icon-view fixed"
                         @click="showPasswordFn('isShowPasswordWx')"></i>
                    </div>
                  </el-form-item>
                  <el-form-item>
                    <el-button type="primary"
                               :loading="loading"
                               @click="save('wxServiceForm')">
                      保存配置
                    </el-button>
                  </el-form-item>
                </el-form>
              </div>
            </el-tab-pane>
            <el-tab-pane label="支付宝"
                         name="2"
                         v-model="active">
              <div class="checkPayment">
                <el-radio v-model="zfbMerchant"
                          label="2"
                          @change="clearFieldsFn('zfbForm')">普通商户支付</el-radio>
                <el-radio v-model="zfbMerchant"
                          label="1"
                          @change="clearFieldsFn('zfbServiceForm')">间连商户支付</el-radio>
              </div>

              <div v-show="zfbMerchant == '2'">
                <el-form ref="zfbForm"
                         :model="zfbForm"
                         :rules="rulesZfbForm"
                         label-width="180px"
                         style="max-width: 650px; padding: 34px 20px 0 20px"
                         @keyup.enter.native="save"
                         @submit.native.prevent>
                  <el-form-item label="支付宝appid:"
                                prop="alipayAppid">
                    <el-input v-model.trim="zfbForm.alipayAppid"
                              show-password
                              placeholder="请输入支付宝appid"
                              clearable />
                  </el-form-item>
                  <el-form-item label="支付宝公钥:"
                                prop="alipayPublicKey">
                    <div class="useMouse">
                      <el-input v-model="zfbForm.alipayPublicKey"
                                @focus="focusInput('zfbFormAlipayPublicKey')"
                                @blur="blurInput('zfbForm')"
                                type="textarea"
                                resize="none"
                                :class="[isShowPasswordAli? 'password':'']"
                                placeholder="请输入支付宝公钥"
                                clearable />
                      <i slot="suffix"
                         style=" color:#c0c4cc"
                         v-if="zfbFormIsShowEyeIconAli"
                         class="el-input__icon el-icon-view fixed"
                         @click="showPasswordFn('isShowPasswordAli')"></i>
                    </div>
                  </el-form-item>
                  <el-form-item label="应用公钥:"
                                prop="appPublicKey">
                    <div class="useMouse">
                      <el-input v-model.trim="zfbForm.appPublicKey"
                                resize="none"
                                @focus="focusInput('zfbFormPublicKey')"
                                @blur="blurInput('zfbForm')"
                                type="textarea"
                                :class="[isShowPassword? 'password':'']"
                                placeholder="请选择应用公钥"
                                clearable />
                      <i slot="suffix"
                         style=" color:#c0c4cc"
                         v-if="zfbFormIsShowEyeIcon"
                         class="el-input__icon el-icon-view fixed"
                         @click="showPasswordFn()"></i>
                    </div>
                  </el-form-item>
                  <el-form-item label="应用私钥:"
                                prop="appPrivateKey">
                    <div class="useMouse">
                      <el-input type="textarea"
                                :class="[isShowPasswordZfb? 'password':'']"
                                show-password
                                @focus="focusInput('zfbFormPrivateKey')"
                                @blur="blurInput('zfbForm')"
                                resize="none"
                                v-model.trim="zfbForm.appPrivateKey"
                                placeholder="请选择应用私钥"
                                clearable />
                      <i slot="suffix"
                         style=" color:#c0c4cc"
                         v-if="zfbFormIsShowEyeIconSp"
                         class="el-input__icon el-icon-view fixed"
                         @click="showPasswordFn('isShowPasswordZfb')"></i>
                    </div>
                  </el-form-item>

                  <el-form-item>
                    <el-button type="primary"
                               :loading="loading"
                               @click="save('zfbForm')">
                      保存配置

                    </el-button>
                  </el-form-item>
                </el-form>
              </div>
              <!-- 支付宝特约子商户 -->
              <div v-show="zfbMerchant == '1'">
                <el-form ref="zfbServiceForm"
                         :model="zfbServiceForm"
                         :rules="rulesZfbServiceForm"
                         label-width="180px"
                         style="max-width: 650px; padding: 34px 20px 0 20px"
                         @keyup.enter.native="save"
                         @submit.native.prevent>
                  <el-form-item label="支付宝appid:"
                                prop="alipayAppid">
                    <el-input v-model.trim="zfbServiceForm.alipayAppid"
                              show-password
                              placeholder="请输入支付宝appid"
                              clearable />
                  </el-form-item>
                  <!-- <el-form-item label="支付宝公钥:"
									prop="alipayPublicKey">
						<el-input v-model="zfbServiceForm.alipayPublicKey"
						show-password
								  placeholder="请输入支付宝公钥"
								  clearable />
					  </el-form-item> -->

                  <!-- <el-form-item label="收款方账户类型:"
									prop="transInType">
						<el-select v-model="zfbServiceForm.transInType"
								   placeholder="请选择结算收款方的账户类型"
								   @change="
						(event) => selsctTransInTypeFn(event)
					  ">
						  <el-option v-for="item in transInTypeOption"
									 :key="item.value"
									 :label="item.label"
									 :value="item.value">
						  </el-option>
						</el-select>
					  </el-form-item> -->

                  <el-form-item v-if="transInStatus"
                                label="结算收款方:"
                                prop="transIn">
                    <el-input v-model.trim="zfbServiceForm.transIn"
                              show-password
                              placeholder='请输入用户的支付宝登录号'
                              clearable />
                    <!-- <span v-if="placeholderType=='请输入用户的支付宝账号对应的支付宝唯一用户号'">注意:【支付宝唯一的用户号需要登陆支付宝商家平台-账户中心-商户号】</span> -->
                  </el-form-item>
                  <el-form-item label="应用公钥:"
                                prop="appPublicKey">
                    <div class="useMouse">
                      <el-input v-model.trim="zfbServiceForm.appPublicKey"
                                @focus="focusInput('zfbServiceFormPublicKey')"
                                @blur="blurInput('zfbServiceForm')"
                                :class="[isShowPasswordSp? 'password':'']"
                                show-password
                                resize="none"
                                type="textarea"
                                placeholder="请选择应用公钥"
                                clearable />
                      <i slot="suffix"
                         style=" color:#c0c4cc"
                         v-if="zfbServiceFormisShowEyeIcon"
                         class="el-input__icon el-icon-view fixed"
                         @click="showPasswordFn('isShowPasswordSp')"></i>
                    </div>
                  </el-form-item>
                  <el-form-item label="应用私钥:"
                                prop="appPrivateKey">
                    <div class="useMouse">
                      <el-input type="textarea"
                                @focus="focusInput('zfbServiceFormPrivateKey')"
                                @blur="blurInput('zfbServiceForm')"
                                :class="[isShowPasswordZfbSp? 'password':'']"
                                resize="none"
                                v-model.trim="zfbServiceForm.appPrivateKey"
                                placeholder="请选择应用私钥"
                                clearable />
                      <i v-if="zfbServiceFormisShowEyeIconSp"
                         slot="suffix"
                         style=" color:#c0c4cc"
                         class="el-input__icon el-icon-view fixed"
                         @click="showPasswordFn('isShowPasswordZfbSp')"></i>
                    </div>
                  </el-form-item>
                  <el-form-item>
                    <el-button type="primary"
                               :loading="loading"
                               @click="save('zfbServiceForm')">
                      保存配置
                    </el-button>
                  </el-form-item>
                </el-form>
              </div>
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
	<script>
import {
  addPayparameter,
  getPayparameter
} from '@/api/system/serviceProxyConfig';
import { rulesWxForm, rulesWxServiceForm, rulesZfbForm, rulesZfbServiceForm } from './constant.js'

import {
  payTypeInsertSelective,
  payTypeSelectByPrimaryKey,
  insertSelective,
  updateByPrimaryKey,
  selectByPrimaryMerchantId,

} from '@/api/douApi/index';
export default {
  name: 'index',
  data () {
    return {
      // 返现时间
      returnCashTime: '',
      //  返现比例
      returnCashRatio: '',
      //   返现金额
      returnCashAmount: '',
      // 返回类型
      returnCashType: '1',
      matchedProps: {},
      loading: false,
      typeloading: false,
      active: '1', // tab页选中
      //   启动微信商户支付
      isWxMerchantPayment: false,
      //  启动 支付宝商户支付
      isZfbMerchantPayment: false,
      //   遮罩层
      isMaskVisible: true,
      // 当前禁用状态
      payStatusObject: {
        // V3商户支付
        v3Status: false,
        // 特约子商户支付
        specialStatus: false,
        // 普通商户支付
        ordinaryStatus: false,
        // 间连商户支付
        Interpenetration: false
      },
      //   isWxFormDisabled: true,
      //   isWxSpFormDisabled: true,
      //   isZfbFormDisabled: true,
      //   isZfbSpFormDisabled: true,
      //   isZfbFormDisabledService: true,
      //   isZfbSpFormDisabledService: true,

      wxPayId: '',
      wxSpPayId: '',
      zfbPayId: '',
      zfbSpPayId: '',
      //   是否为固定金额
      fixed: true,
      //  支付类型id
      typeId: '',
      payStatusArr: [],
      payType: '1',
      wxPayStatus: '',
      payStatus: '',
      zfbPayStatus: '',
      wxPayType: '4', //支付类型 1 微信 2 支付宝
      zfbPayType: '4',


      // 商家id
      merchantId: this.$store.state.user.info.merchantId,
      wxMerchant: '2',
      zfbMerchant: '2',

      // 表单数组
      formArr: ['wxForm', 'wxServiceForm', 'zfbForm', 'zfbServiceForm'],
      //   类型显示
      placeholderType: '',
      //   V3商户支付
      wxForm: {
        appid: '', //appid
        mchid: '', //直连商户号

        appV3Key: '', //APIv3密钥
        merchantSerialNumber: '', //证书序列号
        privateKeyPath: '', // 私钥
      },
      //   特约子商户支付
      wxServiceForm: {
        spAppid: '', // 服务商应用ID
        spMchid: '', //服务商户号
        subMchid: '', //子商户号
        appV3Key: '', //APIv3密钥
        merchantSerialNumber: '', //证书序列号
        privateKeyPath: '', //私钥
      },
      //   普通商户支付
      zfbForm: {
        alipayAppid: '', //支付宝appid
        alipayPublicKey: '', //支付宝公钥
        appPublicKey: '', //应用公钥
        appPrivateKey: '', //应用私钥
      },
      //  间连商户支付
      zfbServiceForm: {
        alipayAppid: '', //支付宝appid
        // alipayPublicKey: '', //支付宝公钥
        appPublicKey: '', //应用公钥
        appPrivateKey: '', //应用私钥
        // 账户类型
        transInType: 'loginName',
        // 结算收款方。
        transIn: '',
      },
      //   结算收款方状态
      transInStatus: true,
      //   账户类型配置
      //   transInTypeOption: [{
      //     label: '支付宝账号对应的支付宝唯一用户号',
      //     value: 'userld'
      //   }, {
      //     label: '结算收款方的银行卡编号',
      //     value: 'cardAliasNo',

      //   }, {
      //     label: '支付宝登录号',
      //     value: 'loginName'
      //   }],
      //   }, {
      //     label: '结算到商户进件时设置的默认结算',
      //     value: 'defaultSettle'
      //   }],
      //  保存禁用
      saveDisable: false,
      rulesWxForm,
      rulesWxServiceForm,
      rulesZfbForm,
      rulesZfbServiceForm: rulesZfbServiceForm,
      payTypeArr: [],
      // 标识
      markers: '',
      maskerValue: '',
      maskerValueWx: '2',
      maskerValueZfb: '',
      isShowPassword: true,
      isShowPasswordZfb: true,
      isShowPasswordZfbSp: true,
      isShowPasswordSp: true,
      isShowPasswordAli: true,
      isShowPasswordWx: true,
      wxFormIsShowEyeIcon: false,
      wxServiceFormIsShowEyeIcon: false,
      zfbFormIsShowEyeIconSp: false,
      zfbFormIsShowEyeIcon: false,
      zfbServiceFormisShowEyeIcon: false,
      zfbServiceFormisShowEyeIconSp: false,
      zfbFormIsShowEyeIconAli: false

    };
  },
  // 路由刷新
  async activated () {
    // 查询是否报存
    this.searchType()
    // 查询是否提交
    this.searchForm()
    // 当文本域有值需要显示小眼睛

  },
  mounted () {

  },
  computed: {
    // 是否开启响应式布局
    styleResponsive () {
      return this.$store.state.theme.styleResponsive;
    },
    saveDisableFn () {
      // 如果微信 支付宝都是禁用状态 显示禁用
      if (this.wxPayType == '4' && this.zfbPayType == '4') { //支付类型 1 微信 2 支付宝 3启动 4 全部关闭
        return this.saveDisable = true
      }
    }

  },
  created () {
  },
  methods: {
    findMatchingProperties (obj1, obj2) {
      console.log(obj1, obj2)
      for (const prop in obj2) {
        if (obj1.hasOwnProperty(prop)) {
          obj2[prop] = obj1[prop];
        }
      }
      console.log(obj2)
    },

    focusInput (type) {

      switch (type) {
        case 'wxForm':
          this.wxFormIsShowEyeIcon = true
          break;
        case 'wxServiceForm':
          this.wxServiceFormIsShowEyeIcon = true
          break;
        case 'zfbFormAlipayPublicKey':
          this.zfbFormIsShowEyeIconAli = true
          break;
        case 'zfbFormPublicKey':
          this.zfbFormIsShowEyeIcon = true
          break;
        case 'zfbFormPrivateKey':

          this.zfbFormIsShowEyeIconSp = true
          break;
        case 'zfbServiceFormPublicKey':
          this.zfbServiceFormisShowEyeIcon = true
          break;
        case 'zfbServiceFormPrivateKey':
          this.zfbServiceFormisShowEyeIconSp = true
          break;
      }
      //   this.wxServiceFormIsShowEyeIcon = true
      //   this.zfbFormIsShowEyeIcon = true
      //   this.zfbFormIsShowEyeIconSp = true
      //   this.zfbServiceFormisShowEyeIcon = true
      //   this.zfbFormIsShowEyeIconAli = true
      //   this.zfbServiceFormisShowEyeIconSp = true
    },
    blurInput (type) {

      if (!this.wxForm.privateKeyPath && type == 'wxForm') {
        this.wxFormIsShowEyeIcon = false
      }
      if (!this.wxServiceForm.privateKeyPath && type == 'wxServiceForm') {
        this.wxServiceFormIsShowEyeIcon = false
      }
      if (!this.zfbForm.alipayPublicKey && type == 'zfbForm') {
        this.zfbFormIsShowEyeIconAli = false
      }
      if (!this.zfbForm.appPublicKey && type == 'zfbForm') {
        this.zfbFormIsShowEyeIcon = false
      }
      if (!this.zfbForm.appPrivateKey && type == 'zfbForm') {
        this.zfbFormIsShowEyeIconSp = false
      }
      if (!this.zfbServiceForm.appPublicKey && type == 'zfbServiceForm') {
        this.zfbServiceFormisShowEyeIcon = false
      }
      if (!this.zfbServiceForm.appPrivateKey && type == 'zfbServiceForm') {
        this.zfbServiceFormisShowEyeIconSp = false
      }
    },
    showEyeValueFn () {
      if (this.wxForm.privateKeyPath) {
        this.wxFormIsShowEyeIcon = true
      }
      if (this.wxServiceForm.privateKeyPath) {
        this.wxServiceFormIsShowEyeIcon = true
      }
      if (this.zfbForm.alipayPublicKey) {
        this.zfbFormIsShowEyeIconAli = true
      }
      if (this.zfbForm.appPublicKey) {
        this.zfbFormIsShowEyeIcon = true
      }
      if (this.zfbForm.appPrivateKey) {
        this.zfbFormIsShowEyeIconSp = true
      }
      if (this.zfbServiceForm.appPublicKey) {
        this.zfbServiceFormisShowEyeIcon = true
      }
      if (this.zfbServiceForm.appPrivateKey) {
        this.zfbServiceFormisShowEyeIconSp = fatruelse
      }
    },
    // enableInput (type) {
    //   this.isWxFormDisabled = false
    //   this.isWxSpFormDisabled = false
    //   if (type == 'appPublicKey') {
    //     this.isZfbFormDisabled = false
    //   }
    //   if (type == 'appPrivateKey') {
    //     this.isZfbSpFormDisabled = false
    //   }
    //   if (type == 'appPublicKeyService') {
    //     this.isZfbFormDisabledService = false
    //   }
    //   if (type == 'appPrivateKeyService') {
    //     this.isZfbSpFormDisabledService = false
    //   }
    // },
    // disableInput (type) {

    //   if (this.wxForm.privateKeyPath) {
    //     this.isWxFormDisabled = true
    //   }
    //   if (this.wxServiceForm.privateKeyPath) {
    //     this.isWxSpFormDisabled = true
    //   }

    //   if (this.zfbForm.appPublicKey && type == 'appPublicKey') {
    //     this.isZfbFormDisabled = true
    //   }
    //   if (this.zfbForm.appPrivateKey && type == 'appPrivateKey') {
    //     this.isZfbSpFormDisabled = true
    //   }
    //   if (this.zfbServiceForm.appPublicKey && type == 'appPublicKeyService') {
    //     this.isZfbFormDisabledService = true
    //   }
    //   if (this.zfbServiceForm.appPrivateKey && type == 'appPrivateKeyService') {
    //     this.isZfbSpFormDisabledService = true
    //   }
    // },

    async searchType () {
      const res = await payTypeSelectByPrimaryKey({
        merchantId: this.merchantId
      })
      console.log(res.data?.id)
      this.typeId = res.data?.id
      //   payStatus // 对查询的内容进行区分
      this.payStatusArr = res.data?.payStatus.split(',')
      console.log(this.payStatusArr)
      if (this.payStatusArr) {
        this.payStatusArr.forEach((item) => {
          if (item == '1' || item == '2') {
            this.wxPayStatus = item
          } else {
            this.zfbPayStatus = item
          }
        })
      }
      // payType  // 如果类型为1 微信 2 支付宝 3 都启用
      if (res.data?.payType == 3) {
        this.wxPayType = '1'
        this.zfbPayType = '2'
        this.isWxMerchantPayment = true
        this.isZfbMerchantPayment = true
      } else if (res.data?.payType == 2) {
        this.wxPayType = '4'
        this.zfbPayType = '2'
        this.isZfbMerchantPayment = true
      } else if (res.data?.payType == 1) {
        this.isWxMerchantPayment = true
        this.wxPayType = '1'
        this.zfbPayType = '4'
      } else {
        this.wxPayType = '4'
        this.zfbPayType = '4'
      }
    },
    async searchForm () {
      const res = await selectByPrimaryMerchantId({
        merchantId: this.$store.state.user.info.merchantId
      });
      console.log(res)
      // 获取到微信支付的id
      this.wxPayId = res.data.wxInfo?.id
      this.wxSpPayId = res.data.wxSpInfo?.id
      this.zfbPayId = res.data.zfbInfo?.id
      this.zfbSpPayId = res.data.zfbSpInfo?.id
      if (res.data.wxInfo?.type == '1' && res.data.wxInfo?.sign == '2') {
        this.findMatchingProperties(res.data.wxInfo
          , this.wxForm)
      }
      if (res.data.wxSpInfo?.type == '1' && res.data.wxSpInfo?.sign == '1') {
        this.findMatchingProperties(res.data.wxSpInfo
          , this.wxServiceForm)
      }
      if (res.data.zfbInfo?.type == '2' && res.data.zfbInfo?.sign == '2') {
        this.findMatchingProperties(res.data.zfbInfo
          , this.zfbForm)
      }
      if (res.data.zfbSpInfo?.type == '2' && res.data.zfbSpInfo?.sign == '1') {
        this.findMatchingProperties(res.data.zfbSpInfo
          , this.zfbServiceForm)
      }
      if (JSON.parse(localStorage.getItem('payType'))) {
        const sign = JSON.parse(localStorage.getItem('payType')).sign;
        const payType = JSON.parse(localStorage.getItem('payType')).payType;
        this.active = payType
        if (payType == '1') {
          this.wxMerchant = sign
        } else {
          this.zfbMerchant = sign
        }
      }
      this.$nextTick(() => {
        this.showEyeValueFn()
      })
    },
    init () {
      if (this.active == '1') {
        getPayparameter({
          payType: this.active
        })
          .then((res) => {
            console.log(res);
          })
          .catch((e) => {
            this.$message.error(e);
          });
      }
    },

    wxPayTypeFn (index) {

      console.log(index);
      if (index == '1') {
        this.wxPayType = '1';
        this.wxPayStatusFn('2');
        this.isWxMerchantPayment = true;
        this.saveDisable = false
      } else {
        this.isWxMerchantPayment = false;
      }
      if (index == '4') {
        this.wxPayType = '4';
        if (this.wxPayType == 4 && this.zfbPayType == 4) {
          this.saveDisable = true
        }
        this.wxPayStatus = ''
      }
    },

    wxPayStatusFn (index) {
      this.wxPayStatus = index

    },
    clearFieldsFn (form) {
      // 清除校验
      console.log(form)
      this.$refs[form].clearValidate();
    },
    cashCashbackFn (index) {
      if (index == '1') {
        this.returnCashType = index;
        // 是否为固定金额
        this.fixed = true;
      } else {
        this.returnCashType = index;
        this.fixed = false;
      }
    },
    zfbPayTypeFn (index) {
      console.log(index);
      if (index == '2') {
        this.zfbPayType = '2';
        this.zfbPayStatusFn('4');
        this.saveDisable = false
        this.isZfbMerchantPayment = true;
      } else {
        this.isZfbMerchantPayment = false;
      }
      if (index == '4') {
        this.zfbPayType = '4';
        if (this.wxPayType == 4 && this.zfbPayType == 4) {
          this.saveDisable = true
        }
        this.zfbPayStatus = ''
      }
    },
    zfbPayStatusFn (index) {
      console.log(index)
      this.zfbPayStatus = index
    },
    // wxPayStatusFn (e) {
    //   let count = 0;
    //   for (let key in this.payStatusObject) {
    //     if (count >= 2) {
    //       break; // 循环前两个属性后退出循环
    //     }
    //     this.payStatusObject[key] = false;
    //     count++;
    //   }
    //   // 微信支付状态
    //   for (let key in this.payStatusObject) {
    //     if (key == e) {
    //       this.payStatusObject[key] = true;
    //     }
    //   }
    //   console.log(this.payStatusObject);
    // },
    // zfbPayStatusFn (e) {
    //   let propertyCount = 0;
    //   const totalProperties = Object.keys(this.payStatusObject).length;
    //   for (let key in this.payStatusObject) {
    //     if (propertyCount + 2 >= totalProperties) {
    //       this.payStatusObject[key] = false;
    //     }
    //     propertyCount++;
    //   }
    //   for (let key in this.payStatusObject) {
    //     if (key == e) {
    //       this.payStatusObject[key] = true;
    //     }
    //   }
    //   console.log(this.payStatusObject);
    // },
    // 点击textArea框
    showPasswordFn (type) {
      if (type == 'isShowPasswordZfb') {
        this.isShowPasswordZfb = !this.isShowPasswordZfb
      } else if (type == 'isShowPasswordZfbSp') {
        this.isShowPasswordZfbSp = !this.isShowPasswordZfbSp
      } else if (type == 'isShowPasswordSp') {
        this.isShowPasswordSp = !this.isShowPasswordSp
      } else if (type == 'isShowPasswordAli') {
        this.isShowPasswordAli = !this.isShowPasswordAli
      } else if (type == 'isShowPasswordWx') {
        this.isShowPasswordWx = !this.isShowPasswordWx
      } else {
        this.isShowPassword = !this.isShowPassword
      }
    },

    handleClick (tab) {
      console.log(tab.name);
      this.payType = String(tab.name)
    },
    resetForm (formName) {
      this.$refs[formName].resetFields();
    },
    // 过滤文本
    filterText (e, form) {
      let privateKey = e.trim()
      let privateKeyPath = privateKey.replace(/^-----BEGIN PRIVATE KEY-----/, "").replace(/-----END PRIVATE KEY-----$/, "")
      if (form == 'wxForm') {
        this.wxForm.privateKeyPath = privateKeyPath.trim();
      } else if (form == 'wxServiceForm') {
        this.wxServiceForm.privateKeyPath = privateKeyPath.trim();
      }
      console.log(privateKeyPath);
    },
    save (formName) {
      this.$refs[formName].validate((valid) => {
        if (!valid) {
          return false;
        }
        for (let i = 0; i < 4; i++) {
          if (!(formName == this.formArr[i])) {
            this.resetForm(this.formArr[i]);
          }
        }
        this.loading = true;
        // 保存的时候存最后保存的sign 和 payType
        console.log((this.payType == '1' && this.wxMerchant == '1'))
        const sumbitForm = this.currentFormFn(this.payType)
        localStorage.setItem('payType', JSON.stringify({ sign: sumbitForm[0][sumbitForm[1]].sign, payType: sumbitForm[0][sumbitForm[1]].type }));
        console.log(sumbitForm[0])
        insertSelective(sumbitForm[0])
          .then((res) => {
            // console.log(res)
            this.$message.success(res.msg);
            this.loading = false;
            this.searchForm()
            // 调用改变按钮(新增修改)的状态
            // this.loadMaskerValue()
          })
          .catch((e) => {
            this.loading = false;
            this.$message.error(e);
          });
      });
    },
    // 当前的提交的form表单
    currentFormFn (payType) {
      if (payType == '1' && this.wxMerchant == '2') {
        return [{
          wxInfo: {
            ...this.wxForm, id: this.wxPayId ? this.wxPayId : '', merchantId: this.merchantId, type: (this.payType == '1' && this.wxMerchant == '2') ? this.payType : '', sign: (this.payType == '1' && this.wxMerchant == '2') ? this.wxMerchant : ''
          },
        }, 'wxInfo']
      } else if (payType == '1' && this.wxMerchant == '1') {
        return [
          {
            wxSpInfo: {
              ...this.wxServiceForm, id: this.wxSpPayId ? this.wxSpPayId : '', merchantId: this.merchantId, type: (this.payType == '1' && this.wxMerchant == '1') ? this.payType : '', sign: (this.payType == '1' && this.wxMerchant == '1') ? this.wxMerchant : ''
            },
          },
          'wxSpInfo'
        ]
      } else if (payType == '2' && this.zfbMerchant == '2') {
        return [
          {
            zfbInfo: {
              ...this.zfbForm, id: this.zfbPayId ? this.zfbPayId : '', merchantId: this.merchantId, type: (this.payType == '2' && this.zfbMerchant == '2') ? this.payType : '', sign: (this.payType == '2' && this.zfbMerchant == '2') ? this.zfbMerchant : ''
            },
          }, 'zfbInfo'
        ]
      } else {
        return [{
          zfbSpInfo: {
            ...this.zfbServiceForm, id: this.zfbSpPayId ? this.zfbSpPayId : '', merchantId: this.merchantId, type: (this.payType == '2' && this.zfbMerchant == '1') ? this.payType : '', sign: (this.payType == '2' && this.zfbMerchant == '1') ? this.zfbMerchant : ''
          },
        }, 'zfbSpInfo']
      }
    },
    saveInfo () {
      this.payTypeArr = [this.wxPayStatus, this.zfbPayStatus]
      console.log(this.payTypeArr)
      if (this.payTypeArr.filter(item => item !== '').length) {
        this.payTypeArr = this.payTypeArr.filter(item => item !== '').join(',')
      } else {
        this.payTypeArr = ''
      }
      this.typeloading = true;

      console.log(this.payTypeArr)
      //   console.log({
      //     payStatus: this.payTypeArr,
      //     merchantId: this.merchantId,
      //     id: this.typeId ? this.typeId : '',
      //     payType: this.payTypeFn(),
      //     // 1.固定金额 2.付款比例
      //     returnCashType: this.returnCashType,
      //     // 返现金额
      //     returnCashAmount: this.returnCashAmount,
      //     // 返现比例
      //     returnCashRatio: this.returnCashRatio,
      //     // 返现时间
      //     returnCashTime: this.returnCashTime
      //   })
      payTypeInsertSelective({
        payStatus: this.payTypeArr,
        merchantId: this.merchantId,
        id: this.typeId ? this.typeId : '',
        payType: this.payTypeFn(),
        // // 1.固定金额 2.付款比例
        // returnCashType: this.returnCashType,
        // // 返现金额
        // returnCashAmount: this.returnCashAmount,
        // // 返现比例
        // returnCashRatio: this.returnCashRatio,
        // // 返现时间
        // returnCashTime: this.returnCashTime
      })
        .then((res) => {

          this.$message.success(res.msg);
          this.typeloading = false;
          // 查询是否保存
          this.searchType()
        })
        .catch((e) => {
          this.typeloading = false;
          this.$message.error(e);
        });
    },

    payTypeFn () {
      if (this.wxPayType == '4' && this.zfbPayType == '4') {
        // 不启动
        return '';
      } else if (this.wxPayType == '1' && this.zfbPayType == '4') {
        return '1';
      } else if (this.wxPayType == '4' && this.zfbPayType == '2') {
        return '2';
      } else {
        return '3';
      }
    }
  }
};
	</script>
	<style lang="less" scoped>
.useMouse {
  position: relative;
  .fixed {
    position: absolute;
    right: 7px;
    top: -3px;
  }
  .password {
    -webkit-text-security: disc !important;
  }
}
.ele-body {
  min-width: 400px;
}
/deep/.el-loading-spinner {
  display: none;
}
/deep/ .el-loading-mask {
  background-color: rgb(243, 243, 243);
}
.wxFormMask {
  position: relative;
  width: 470px;
  height: 120px;
  background-color: rgba(37, 36, 36, 0.5);
  z-index: 999;
}
/deep/.delInput input::-webkit-outer-spin-button,
/deep/.delInput input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
}
/deep/.delInput input[type='number'] {
  -moz-appearance: textfield;
}

/deep/ .el-input__icon {
  height: 14px;
}
span {
  color: #b4b4b4;
}
:deep(.el-textarea__inner) {
  height: 120px;
}
/* tab 页签 */
.user-info-tabs {
  :deep(.el-tabs__nav-wrap) {
    padding-left: 24px;
  }

  :deep(.el-tabs__item) {
    height: 50px;
    line-height: 50px;
    font-size: 15px;
  }
}
.checkPayment {
  margin: 30px 0px 0px 24px;
}
</style>
	